package com.zjw.zy.ext

import android.app.Activity
import com.zjw.zy.smi.JustWithIt
import com.zjw.zy.utils.AppUtils
import com.zjw.zy.utils.DialogUtils
import com.zjw.zy.utils.LogUtils

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2022/10/21 17:02
 * @description：
 */


fun Any?.alertConfirm(
    title: String = "",
    message: String = "",
    activity: Activity = AppUtils.getMainActivity(),
    autoCancel: Boolean = true,
    call: JustWithIt<Boolean>? = null
) {
    DialogUtils.alertConfirm(title, message, activity, autoCancel, call)
}


fun Any?.alertInput(
    title: String = "",
    text: String = "",
    activity: Activity = AppUtils.getMainActivity(),
    autoCancel: Boolean = true,
    call: JustWithIt<String>? = null
) {
    DialogUtils.alertInput(title, text, activity, autoCancel, call)
}

fun Any.safeCall(task: () -> Unit) {
    try {
        task()
    } catch (ignore: Throwable) {
        LogUtils.e(this::class.java.name, ignore.message)
    }
}